﻿@model ManufacturerListModel
@{
    var defaultGridPageSize = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().DefaultGridPageSize;
    var gridPageSizes = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().GridPageSizes;

    //page title
    ViewBag.Title = T("Admin.Catalog.Manufacturers").Text;
}
<div class="section-header">
    <div class="title">
        <img src="@Url.Content("~/Administration/Content/images/ico-catalog.png")" alt="" />
        @T("Admin.Catalog.Manufacturers")
    </div>
    <div class="options">
        <a href="@Url.Action("Create")" class="k-button">@T("Admin.Common.AddNew")</a>
        <a href="@Url.Action("ExportXml")" class="k-button">@T("Admin.Common.ExportToXml")</a>
    </div>
</div>
<table width="100%">
    <tr>
        <td class="adminTitle">
            @Html.NopLabelFor(model => model.SearchManufacturerName):
        </td>
        <td class="adminData">
            @Html.EditorFor(model => model.SearchManufacturerName)
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <input type="button" id="btnSearch" class="k-button" value="@T("Admin.Common.Search")" />
        </td>
    </tr>
</table>
<p></p>
<table class="adminContent">
    <tr>
        <td>
            <div id="manufacturers-grid"></div>

            <script>
                $(document).ready(function () {
                    $("#manufacturers-grid").kendoGrid({
                        dataSource: {
                            type: "json",
                            transport: {
                                read: {
                                    url: "@Html.Raw(Url.Action("List", "Manufacturer"))",
                                    type: "POST",
                                    dataType: "json",
                                    data: additionalData
                                }
                            },
                            schema: {
                                data: "Data",
                                total: "Total",
                                errors: "Errors"
                            },
                            error: function(e) {
                                display_kendoui_grid_error(e);
                                // Cancel the changes
                                this.cancelChanges();
                            },
                            pageSize: @(defaultGridPageSize),
                            serverPaging: true,
                            serverFiltering: true,
                            serverSorting: true
                        },
                        pageable: {
                            refresh: true,
                            pageSizes: [@(gridPageSizes)]
                        },
                        editable: {
                            confirmation: false,
                            mode: "inline"
                        },
                        scrollable: false,
                        columns: [{
                            field: "Name",
                            title: "@T("Admin.Catalog.Manufacturers.Fields.Name")"
                        }, {
                            field: "Published",
                            title: "@T("Admin.Catalog.Manufacturers.Fields.Published")",
                            width: 100,
                            headerAttributes: { style: "text-align:center" },
                            attributes: { style: "text-align:center" },
                            template: '<img src="@Url.Content("~/Administration/Content/images/")active-#=Published#.gif" />'
                        }, {
                            field: "DisplayOrder",
                            title: "@T("Admin.Catalog.Manufacturers.Fields.DisplayOrder")",
                            width: 100
                        }, {
                            field: "Id",
                            title: "@T("Admin.Common.Edit")",
                            width: 100,
                            template: '<a href="Edit/#=Id#">@T("Admin.Common.Edit")</a>'
                        }]
                    });
                });
            </script>

            <script type="text/javascript">
                $(document).ready(function () {
                    //search button
                    $('#btnSearch').click(function () {
                        //search
                        var grid = $('#manufacturers-grid').data('kendoGrid');
                        grid.dataSource.page(1); //new search. Set page size to 1
                        grid.dataSource.read();
                        return false;
                    });

                    $("#@Html.FieldIdFor(model => model.SearchManufacturerName)").keydown(function (event) {
                        if (event.keyCode == 13) {
                            $("#btnSearch").click();
                            return false;
                        }
                    });
                });

                function additionalData() {
                    return {
                        SearchManufacturerName: $('#@Html.FieldIdFor(model => model.SearchManufacturerName)').val()
                    };
                }
            </script>
        </td>
    </tr>
</table>